<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: Debugger</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_debugger.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Debugger </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/debugger/</p>
<p>The <code>CDebugger</code> implements common debugging functionality for scripts, e.g. setting breakpoints, stepping through the code, examining values of variables, etc.</p>
<p>To use the debugger the line callback should be set in the context. This will allow the debugger to take over whenever a breakpoint is reached, so the script can be debugged.</p>
<p>By default the debugger uses the standard in and standard out streams to interact with the user, but this can be easily overloaded by deriving from the <code>CDebugger</code> class and implementing the methods <code>TakeCommands</code> and <code>Output</code>. With this it is possible to implement a graphical interface, or even remote debugging for an application.</p>
<p>The application developer may also be interested in overriding the default <code>ToString</code> method to implement ways to visualize application registered types in an easier way.</p>
<dl class="see"><dt><b>See also:</b></dt><dd>The sample <a class="el" href="doc_samples_asrun.html">Commandline runner</a> for a complete example of how to use the debugger</dd></dl>
<h2><a class="anchor" id="doc_addon_ctxmgr_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CDebugger
{
<span class="keyword">public</span>:
  CDebugger();
  <span class="keyword">virtual</span> ~CDebugger();

  <span class="comment">// User interaction</span>
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> TakeCommands(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Output(<span class="keyword">const</span> std::string &amp;str);

  <span class="comment">// Line callback invoked by context</span>
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> LineCallback(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);

  <span class="comment">// Commands</span>
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> PrintHelp();
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> AddFileBreakPoint(<span class="keyword">const</span> std::string &amp;file, <span class="keywordtype">int</span> lineNbr);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> AddFuncBreakPoint(<span class="keyword">const</span> std::string &amp;func);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ListBreakPoints();
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ListLocalVariables(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ListGlobalVariables(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ListMemberProperties(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> ListStatistics(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> PrintCallstack(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">void</span> PrintValue(<span class="keyword">const</span> std::string &amp;expr, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);

  <span class="comment">// Helpers</span>
  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> InterpretCommand(<span class="keyword">const</span> std::string &amp;cmd, <a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> CheckBreakPoint(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx);
  <span class="keyword">virtual</span> std::string ToString(<span class="keywordtype">void</span> *value, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> typeId, <span class="keywordtype">bool</span> expandMembers, <a class="code" href="classas_i_script_engine.html" title="The engine interface.">asIScriptEngine</a> *engine);
};
</pre></div><h2><a class="anchor" id="doc_addon_debugger_1"></a>
Example usage</h2>
<div class="fragment"><pre class="fragment">CDebugger dbg;
<span class="keywordtype">int</span> ExecuteWithDebug(<a class="code" href="classas_i_script_context.html" title="The interface to the virtual machine.">asIScriptContext</a> *ctx)
{
  <span class="comment">// Tell the context to invoke the debugger&#39;s line callback</span>
  ctx-&gt;<a class="code" href="classas_i_script_context.html#ae2747f643bf9a07364f922c460ef57dd" title="Sets a line callback function. The function will be called for each executed script statement...">SetLineCallback</a>(<a class="code" href="angelscript_8h.html#a7345e6b3afabec24efd0ff77886d49a6" title="Returns an asSFuncPtr representing the class method specified by class and method name...">asMETHOD</a>(CDebugger, LineCallback), dbg, <a class="code" href="angelscript_8h.html#a3ec92ea3c4762e44c2df788ceccdd1e4aea516c8742acc1edff6a43dc1bb09e96" title="A thiscall class method.">asCALL_THISCALL</a>);

  <span class="comment">// Allow the user to initialize the debugging before moving on</span>
  dbg.TakeCommands(ctx);

  <span class="comment">// Execute the script normally. If a breakpoint is reached the </span>
  <span class="comment">// debugger will take over the control loop.</span>
  <span class="keywordflow">return</span> ctx-&gt;<a class="code" href="classas_i_script_context.html#a8e52894432737acac2e1a422e496bf84" title="Executes the prepared function.">Execute</a>();
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
